package com.weixin.paleituo.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.activity.GoodsDetailsActivity;
import com.weixin.paleituo.base.BaseRecycleAdapter;
import com.weixin.paleituo.bean.Goods;
import com.weixin.paleituo.help.RecycleViewHolder;
import com.weixin.paleituo.util.StringUtils;
import com.weixin.paleituo.util.UIUtils;

import java.util.List;

/**
 * Author yichao
 * Time  2018/3/19 17:59
 * Dest  商品分类
 */

public class ClassifyGoodsRecycleAdapter extends BaseRecycleAdapter<Goods> {

    private ImageView mImageView;
    private TextView mTvName;
    private TextView mTvMoney;
    private TextView mTvSales;
    private TextView mMTvStore;
    private ImageView mIvVip;
    private TextView mTvnormalMoney;

    public ClassifyGoodsRecycleAdapter(Context context, List<Goods> datas) {
        super(context, datas, R.layout.item_classify_goods);
    }
    @Override
    protected void setData(RecycleViewHolder holder, final Goods goods, int position) {
        mImageView = holder.getItemView(R.id.iv_item_classify_goods);
        mTvName = holder.getItemView(R.id.tv_name_item_classify_goods);
        mTvMoney = holder.getItemView(R.id.tv_money_item_classify_goods);
        mTvSales = holder.getItemView(R.id.tv_sales_item_classify_goods);
        mMTvStore = holder.getItemView(R.id.tv_store_item_classify_goods);
        mIvVip = holder.getItemView(R.id.iv_vip_item_classify_goods);
        mTvnormalMoney = holder.getItemView(R.id.tv_normalmoney_item_classify_goods);
        String specialSales = goods.getSpecialSales();
        if (!StringUtils.isEmpty(specialSales)){
            mIvVip.setVisibility(View.VISIBLE);
            mTvMoney.setTextColor(UIUtils.getColor(R.color.c_29CE7E));
            mTvMoney.setText("￥"+UIUtils.getMoney(Double.valueOf(specialSales)));
            mTvnormalMoney.setText("￥"+UIUtils.getMoney(Double.valueOf(goods.getPrice())));
            mTvnormalMoney.setVisibility(View.VISIBLE);

        }else {
            mTvnormalMoney.setVisibility(View.INVISIBLE);
            mIvVip.setVisibility(View.INVISIBLE);
            mTvMoney.setTextColor(UIUtils.getColor(R.color.c_ed5240));
            mTvMoney.setText("￥"+UIUtils.getMoney(Double.valueOf(goods.getPrice())));
        }
        UIUtils.loadImageView(mContext,goods.getListUrl(),mImageView);
        mTvName.setText(goods.getGoodsName()+"");
        mMTvStore.setText(goods.getStoreName()+"");
        if (goods.getGoodsSalenum()>0){
            mTvSales.setText("已售"+goods.getGoodsSalenum());
            mTvSales.setVisibility(View.VISIBLE);
        }else {
            mTvSales.setVisibility(View.INVISIBLE);
        }

        holder.mItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GoodsDetailsActivity.startActivity(mContext,goods.getId());
            }
        });

    }
}
